package com.huatech.core.amqp;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
	
    @Bean
    public Exchange bootExchange(){
        return new DirectExchange(RabbitConstant.EXCHANGE_DIRECT, true, false);
    }

    @Bean
    public Queue bootQueue(){
        return new Queue(RabbitConstant.QUEUE_USER, true);
    }
    
    @Bean
    public SimpleRabbitListenerContainerFactory containerFactory(SimpleRabbitListenerContainerFactory factory) {
    	factory.setMessageConverter(new Jackson2JsonMessageConverter());
    	return factory;
    }
    
//    @Bean
//    public SimpleMessageListenerContainer simpleMessageListenerContainer(ConnectionFactory connectionFactory){
//        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
//        container.setMessageConverter(new Jackson2JsonMessageConverter());
//        // 默认采用下面的这种转换器
//        // container.setMessageConverter(new SimpleMessageConverter());
//        return container;
//    }
}